exports.organizationActivityBrowing = function (req, res) {

    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var skip  =  restfulParams.skip == undefined  ? 0 : restfulParams.skip;
    var limit =  restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;


    //任务流创建
    async.waterfall([
            
        function (cb) {
            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.searchOrganizationActivityBrowsing + "/ubh_uid/" + restfulParams.u_id + "/skip/"+skip+"/limit/" + limit,
                    method: 'POST'
                },
                function (err, data) {
                    
                    //判断是否有错误信息
                    if (err) {
                        return cb(err, data);
                    }

                    resultData = data.data;
                    cb();
                }
            );

        },

        //查询对应id的活动
        function(cb){

            //创建添加任务
            var tasks = [];

            //循环节点列表
            resultData.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {

                    //拼团
                    if(item.oa_type == 0){

                        R.SEND_HTTP(
                            req,
                            {
                                url    : CORE_APIConfig.coreAPI.search_bulk_purchase_activity_config + "/bpac_oaid/" + item.oa_id,
                                method : 'POST',
                                data : {
                                    fields:["bpac_id","bpac_new_price"].join(",")
                                }
                            },
                            function (err, data) {

                                item.price =  data.data[0].bpac_new_price;

                                cb();
                            }
                        );
                        //促销
                    }else if(item.oa_type == 5){

                        R.SEND_HTTP(
                            req,
                            {
                                url    : CORE_APIConfig.coreAPI.search_discounts_activity_config + "/dac_oaid/" + item.oa_id,
                                method : 'POST',
                                data : {
                                    fields:["dac_id","dac_new_price"].join(",")
                                }
                            },
                            function (err, data) {

                                item.price =  data.data[0].dac_new_price;

                                cb();
                            }
                        );
                    }else{
                        item.price =0;
                        cb();
                    }

                });

            });

            async.waterfall(tasks, cb);

        }

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}